package com.qfedu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qfedu.dao.UserDao;
import com.qfedu.entity.User;
import com.qfedu.service.intf.UserService;
import com.qfedu.vo.PageVo;
import com.qfedu.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserDao dao;

    @Override
    public R add(User user) {
        if(dao.add(user)>0){
            //成功
            return new R(1,"OK",null);
        }else {
            return new R(0,"FAIL",null);
        }
    }


    @Override
    public PageVo queryPage(int page, int limit) {
        //1.开启分页
        PageHelper.startPage(page, limit);
        //2.执行分页查询
        PageInfo<User> pageInfo=new PageInfo<>(dao.all());
        System.out.println(pageInfo.getList());
        //3.返回结果
        return new PageVo(0,"OK", pageInfo.getTotal(), pageInfo.getList());
    }
}
